Page({
  data: {
    sId: null,
    showYear: false, //控制下拉列表的显示隐藏，false隐藏、true显示
    showTerm: false,
    yearSelect: ['2017-2018', '2016-2017'], //下拉学年数据
    termSelect: ['1', '2', '3'], //下拉学期数据
    yearIndex: 0, //下拉列表下标
    termIndex: 0,
    Cookie: null,
    xm: null,
    courseList: null
  },
  // 点击下拉显示框
  selectTap(e) {
    console.log(e)
    var _which = e.currentTarget.dataset.which;
    if (_which === "year") {
      this.setData({
        showYear: !this.data.showYear
      });
    } else {
      this.setData({
        showTerm: !this.data.showTerm
      });
    }

  },
  // 学年下拉列表选中事件
  yearOptionTap(e) {
    let Index = e.currentTarget.dataset.index; //获取点击的下拉列表的下标
    this.setData({
      yearIndex: Index,
      showYear: !this.data.showYear
    });
  },

  // 学期下拉列表选中事件
  termOptionTap(e) {
    let Index = e.currentTarget.dataset.index; //获取点击的下拉列表的下标
    this.setData({
      termIndex: Index,
      showTerm: !this.data.showTerm
    });
  },
  onLoad: function (options) {

    console.log(options)
    console.log(decodeURI(options.xm))
    var that = this;
    var pages = getCurrentPages();//获取当前页面信息栈
    var prevPage = pages[pages.length - 2]//获取上一个页面信息栈
    var _cookie = prevPage.data.Cookie;
    console.log(_cookie)
    that.setData({
      Cookie: _cookie,
      xm: decodeURI(options.xm),
      sId: options.sId,
    });

  },
  query() {
    var that = this;
    wx.showLoading({
      title: '请稍后...',
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 3000)
    //查询成绩
    wx.request({
      url: 'https://geek-team.xin/grade/getGrade',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        'xq': that.data.termSelect[that.data.termIndex],
        'xn': that.data.yearSelect[that.data.yearIndex],
        'xm': that.data.xm,
        'username': that.data.sId,
        'cookie': that.data.Cookie
      },
      success(e) {
        console.log(e)
        that.setData({
          courseList: e.data
        })
      },
    })
  }
})